import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';

class HomeContent extends StatefulWidget {
  const HomeContent({Key? key}) : super(key: key);

  @override
  State<HomeContent> createState() => _HomeContentState();
}

class _HomeContentState extends State<HomeContent> {
  late TextEditingController searchController = TextEditingController();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    searchController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var descTextStyle = const TextStyle(color: Colors.white);
    final List<String> imageList = [
      "https://cdn.pixabay.com/photo/2017/12/03/18/04/christmas-balls-2995437_960_720.jpg",
      "https://cdn.pixabay.com/photo/2017/12/13/00/23/christmas-3015776_960_720.jpg",
      "https://cdn.pixabay.com/photo/2019/12/19/10/55/christmas-market-4705877_960_720.jpg",
      "https://cdn.pixabay.com/photo/2019/12/20/00/03/road-4707345_960_720.jpg",
      "https://cdn.pixabay.com/photo/2019/12/22/04/18/x-mas-4711785__340.jpg",
      "https://cdn.pixabay.com/photo/2016/11/22/07/09/spruce-1848543__340.jpg"
    ];
    return Scaffold(
      appBar: GFAppBar(
        leading: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            const Text('28C', style: TextStyle(fontSize: 10)),
            Row(
              children: const [
                Text('宝安区', style: TextStyle(fontSize: 10)),
                Icon(Icons.arrow_right,size: 20,)
              ],
            )
          ],
        ),
        searchBar: true,
        searchHintText: "搜索站点/服务/咨询",
        onChanged: (e) {
        },
        // ignore: avoid_print
        onSubmitted: ((value) => {print(value)}),
        searchHintStyle: const TextStyle(
          fontSize: 12,
        ),
        searchTextStyle: const TextStyle(fontSize: 12),
        searchController: searchController,
        bottom: PreferredSize(
          preferredSize: const Size.fromHeight(60),
          child: DefaultTextStyle.merge(
            style: descTextStyle,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: const [
                Tab(
                  icon: Icon(
                    Icons.line_axis,
                    color: Colors.white,
                  ),
                  child: Text(
                    '地铁线路图',
                  ),
                ),
                Tab(
                  icon: Icon(
                    Icons.qr_code,
                    color: Colors.white,
                  ),
                  child: Text(
                    '乘车码',
                  ),
                ),
                Tab(
                  icon: Icon(
                    Icons.location_city,
                    color: Colors.white,
                  ),
                  child: Text(
                    '出行规划',
                  ),
                ),
              ],
            ),
          ),
        ),
        actions: <Widget>[
          GFButton(
            padding: const EdgeInsets.all(0.0),
            child: const Text(
              '搜索',
              style: TextStyle(fontSize: 10),
            ),
            onPressed: () {
            },
            type: GFButtonType.transparent,
          ),
          GFIconButton(
            padding: const EdgeInsets.all(0.0),
            icon: const Icon(
              Icons.message,
              color: Colors.white,
              size: 10,
            ),
            onPressed: () {},
            type: GFButtonType.transparent,
          ),
          GFIconButton(
            padding: const EdgeInsets.all(0.0),
            icon: const Icon(
              Icons.scanner,
              color: Colors.white,
              size: 10,
            ),
            onPressed: () {},
            type: GFButtonType.transparent,
          ),
        ],
      ),
      body: ListView(
        children: [
          GFCard(
            boxFit: BoxFit.cover,
            content: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: const [
                    Tab(
                      icon: Icon(Icons.record_voice_over),
                      child: Text(
                        '站点详情',
                      ),
                    ),
                    Tab(
                      icon: Icon(Icons.airplane_ticket),
                      child: Text(
                        '末班可达',
                      ),
                    ),
                    Tab(
                      icon: Icon(Icons.location_city),
                      child: Text(
                        '列车位置',
                      ),
                    ),
                    Tab(
                      icon: Icon(Icons.card_giftcard),
                      child: Text(
                        '到站提醒',
                      ),
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: const [
                    Tab(
                      icon: Icon(Icons.record_voice_over),
                      child: Text(
                        '站内导航',
                      ),
                    ),
                    Tab(
                      icon: Icon(Icons.airplane_ticket),
                      child: Text(
                        '乘车发票',
                      ),
                    ),
                    Tab(
                      icon: Icon(Icons.location_city),
                      child: Text(
                        '延误证明',
                      ),
                    ),
                    Tab(
                      icon: Icon(Icons.card_giftcard),
                      child: Text(
                        '更多',
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          GFCarousel(
            items: imageList.map(
              (url) {
                return Container(
                  margin: const EdgeInsets.all(0.0),
                  child: ClipRRect(
                    borderRadius: const BorderRadius.all(Radius.circular(5.0)),
                    child: Image.network(url,
                        fit: BoxFit.cover,
                        width: MediaQuery.of(context).size.width),
                  ),
                );
              },
            ).toList(),
            onPageChanged: (index) {
              setState(() {
                print(index);
              });
            },
          )
        ],
      ),
    );
  }
}
